/*************************************************
* Title：TinyToolKit
* Author：Opportunity 
* Describe：单例模板
* CreateTime：2020-04-05 19:29:23
* Version：1.0
* Modify Recorder：
*************************************************/
namespace TinyToolKit
{
    /// <summary>
    /// 单例模板
    /// </summary>
    /// <typeparam name="T">需要实现单例的类</typeparam>
    public abstract class TSingleton<T> where T : TSingleton<T>,new()
    {
        protected static T _instance;
        private static readonly object _Lock = new object(); 

        protected TSingleton() { }

        public static T Instance
        {
            get
            {
                lock (_Lock)
                {
                    if (_instance == null)
                        _instance = new T();
                }
                return _instance;
            }
        }

        public virtual void Dispose()
        {
            _instance = null;
        }
    }
}
